import request from "@/utils/request";
import type { SysUserAuthInfo, SysUserDTO, SysUserFiltDTO, SysUserVO } from "./sysUserType";
import type { IdDTO, PageQueryDTO, PageQueryVO } from "../type/baseType";

enum URL {
    URL_USER_BASE = '/user',
    URL_USER_PAGE = URL_USER_BASE + '/page',
    URL_USER_AUTHINFO = URL_USER_BASE + '/authInfo',
    URL_USER_RESET_PASSWORD = URL_USER_BASE + '/reset-password'
}

/**
 * 增加User
 * @param sysUserDTO
 * @returns 
 */
export const addUser = (sysUserDTO: SysUserDTO):
    Promise<undefined> =>
    request.post(URL.URL_USER_BASE, sysUserDTO)

/**
 * 删除User
 * @param id
 * @returns 
 */
export const deleteUser = (id: IdDTO):
    Promise<undefined> =>
    request.delete(`${URL.URL_USER_BASE}/${id.id}`)

/**
 * 修改User
 * @param id
 * @param sysUserDTO
 * @returns 
 */
export const updateUser = (id: IdDTO, sysUserDTO: SysUserDTO):
    Promise<undefined> =>
    request.put(`${URL.URL_USER_BASE}/${id.id}`, sysUserDTO)

/**
 * 重置密码
 * @param id
 * @returns 
 */
export const resetUserPassword = (id: IdDTO):
    Promise<undefined> =>
    request.put(`${URL.URL_USER_RESET_PASSWORD}/${id.id}`)

/**
 * 查询User
 * @param id
 * @returns 
 */
export const queryUser = (id: IdDTO):
    Promise<SysUserVO> =>
    request.get(`${URL.URL_USER_BASE}/${id.id}`)

/**
 * 分页查询当前登录用户有权访问的所有用户列表
 * @param pageQueryDTO
 * @returns 
 */
export const queryUserPage = (pageQueryDTO: PageQueryDTO<SysUserFiltDTO>):
    Promise<PageQueryVO<SysUserVO>> =>
    request.get(URL.URL_USER_PAGE, {
        params: {
            pageNum: pageQueryDTO.pageNum,
            pageSize: pageQueryDTO.pageSize,
            ...pageQueryDTO.param
        }
    })

/**
 * 获取用户认证信息
 * @returns 
 */
export const getUserAuthInfo = ():
    Promise<SysUserAuthInfo> =>
    request.get(URL.URL_USER_AUTHINFO)